****************************************************************************************************************************************************************
*REPLICATION MATERIAL FOR 
*Rudolph, L., & Wagner, M. 
*Europe’s Migration Crisis: Local Contact and Out-Group Hostility
*forthcoming in European Journal of Political Research 
*
*Version 1.0, written 2021-02-20 by Lukas Rudolph
****************************************************************************************************************************************************************

****************************************************************************************************************************************************************
/*
Datasets used:
datasources\master.dta
datasources\placebo2013.dta
*/
****************************************************************************************************************************************************************

****************************************************************************************************************************************************************
*This Do-File replicates the results presented in 
/*
Figure 2:	Perceived presence of and contact with asylum seekers
Figure 3: 	Which type of contact with asylum seekers changes?
Figure 4: 	Attitudinal effects of asylum seeker housing
Figure 5: 	Effects of housing asylum seekers on party preferences and voting behavior

Table A3.1: Balance in 2013 survey by 2015/16 asylum take-up for three groups
Table A3.2: Placebo test with weights based on municipality and individual characteristics
Table A4.1: Summary statistics for variables used in entropy balancing
Table A4.2: Does the treatment increase presence perception of/contact with refugees
Table A4.3: Type of contact that changes
Table A4.4: Impact on group threat
Table A4.5: Effects on attitudes towards refugees/asylum seekers
Table A4.6: Effects on broader attitudes
Table A4.7: Impact on political preferences and voting behavior
Table A4.8: Side-by-side comparison of linear vs. logistic regression estimates for binary dependent variables of Figure 4 and 5
Table A5.1: Results for impact on contact, attitudes and behavior with nearest neighbour matching
Table A5.2: Effects of contact type by treatment exposure (with population weights)
Table A5.3: Results for impact on refugee and immigration attitudes - unweighted results - part 1
Table A5.4: Results for impact on refugee and immigration attitudes - unweighted results - part 2
Table A6.1: Subgroup results: Male/female
Table A6.2: Subgroup results: High/low education
Table A6.3: Subgroup results: Above/below median age
Table A6.4: Subgroup results: Above/below median share of immigrants in municipality pre-2015
Table A7.1: Effects of contact type by treatment exposure
Table A8.1: Campaign Effects W5

Figure A1.1: Attitudinal effects
Figure A4.1: Weighted distribution of contact variable in municipalities with and without asylum seekers
Figure A4.2: Weighted distribution of group threat variable in municipalities with and without asylum seekers
Figure A5.1: Effects under different specifications of the entropy balancing
Figure A5.2: Perceived presence and contact by treatment subgroups (with population weights)
Figure A5.3: Attitudinal effects (with population weights)
Figure A5.4: Effects on voting behavior (with population weights)
Figure A6.1: Attitudinal effects in Upper Austria
Figure A6.2: Effects on vote choice in Upper Austria
Figure A7.1: Distribution of intensive margin
Figure A7.2: Perceived presence and contact by treatment subgroups
Figure A7.3: Attitudinal effects by high and low treatment exposure
Figure A7.4: Effects on voting behavior by high and low treatment exposure
Figure A8.1: Effects of asylum seeker presence on campaign contact
Figure A8.2: Effects of asylum seeker presence on campaign contact (by treatment subgroups)
*/
****************************************************************************************************************************************************************

****************************************************************************************************************************************************************
*prepare Stata

version 14 
set more off
clear all
capture log close

/* if not already installed: install the following Stata packages in order to run this do-file: 
ssc install ebalance, replace    // ebalance Package by Jens Hainmueller and Yiqing Xu
ssc install grstyle, replace    // grstyle Package by Ben Jann
ssc install colrspace, replace  // colrspace Package by Ben Jann
ssc install coefplot, replace   // coefplot Package by Ben Jann
ssc install blindschemes        // blindscheme Package by Daniel Bischof
ssc install estout, replace     // estout package by Ben Jann
ssc install byhist              // byhist package by Austin Nichols
*/


****************************************************************************************************************************************************************
*set working directory to folder containing the subfolder with replication data "datasources" and subfolders "tables" and "figures" 

*cd " " 

****************************************************************************************************************************************************************
*set global macros

global vmtab = "tables" // path to folder where tables are saved
global vmfig = "figures" // path to folder where figures are saved

****************************************************************************************************************************************************************
*set colorstyle grstyle for figures
grstyle init
grstyle set color Dark2  
grstyle set legend, nobox 


****************************************************************************************************************************************************************
*load dataset for Figures
use datasources\master.dta, clear

*______________________________________________________________________________________________________________
****************************************************************************************************************************************************************
*Creation of Entropy Weights
*______________________________________________________________________________________________________________
****************************************************************************************************************************************************************

*****
*generate globals and entropy weights

global sociodem_cont2 = "male age kids_nr religion union migrant goodincome"
global sociodem_cat2 = "i.land i.areaofresidence i.employment i.education"
global sociodem_cat_indic2 = "*employment *education *areaofresidence"

global agg = "to13 fpoe13 fpoe_trend to_trend" 
global municip_new = "lnpop15 pop15del3_sh forpop15_sh unemp15_sh unemp15_sh_del3 forpop15_sh_del3"

global an = "contact refugees"
global se = "robust"

*** weights from entropy balancing drawing on aggregate level and individual level variables 
capture drop weight2
ebalance noasyl  $agg $sociodem_cont2 $sociodem_cat2 $municip_new /// 
, targets(1)    
gen weight2 = _webal

***weights from entropy balancing drawing on aggregate level and individual level variables 
capture drop weight2_pop
ebalance noasyl  $agg $sociodem_cont2 $sociodem_cat2 $municip_new /// 
, targets(1)  basewt(w1_weightd)   
gen weight2_pop = _webal

global weight2 = "[pw=weight2]"
global weight2_pop = "[pw=weight2pop]"

*** entropy weights for low/high exposure

capture drop weight2_low
ebalance noasylvslow  $agg $sociodem_cont2 $sociodem_cat2 $municip_new /// 
, targets(1)    
gen weight2_low = _webal

capture drop weight2_high
ebalance noasylvshigh  $agg $sociodem_cont2 $sociodem_cat2 $municip_new /// 
, targets(1)  tolerance(1.165)    
gen weight2_high = _webal

global weight2_low = "[pw=weight2_low]"
global weight2_high = "[pw=weight2_high]"

*generate additional relevant variables
cumul revthreat2 if asylum==0 [aweight=weight2], gen(cumnoasyl)
cumul revthreat2 if asylum==1 [aweight=weight2], gen(cumasyl)


*______________________________________________________________________________________________________________
****************************************************************************************************************************************************************
*FIGURES IN MAIN PAPER
*______________________________________________________________________________________________________________
****************************************************************************************************************************************************************

********************************************************************************
*Figure 1: Aslyum seeker presence in municipalities in Austria in 2016
********************************************************************************

* Not generated in Stata.

********************************************************************************
*Figure 2: Perceived presence of and contact with asylum seekers
********************************************************************************

***
global an = "contact_bin contact refugees"   
***

foreach x in $an {
svyset randomid [pweight=weight2]
eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new  
}

coefplot(contact_bin, offset(0.125)) (refugees, offset(-0.375)), keep(asylum)	      ///
scheme(plotplain) legend(off) levels(95 90) msymbol(o) mcolor(black) xline(0)   	  ///
ciopts(lcolor(black black)) xlabel(0(.05).35) graphregion(margin(0 0 +15 +15)) 		  ///
ylabel(none) yscale(range(0.5 1.75)) yline(1.15) mlcolor(black)	xscale(range(0 .35))  ///
text(1 .09 "Frequency of spoken contact > monthly? (0-1)", size(small) j(l))     ///
text(1.5 .21 "Presence of asylum seekers noted? (0-1)", size(small) j(l))    

graph export figures\Fig2.png, width(4000) replace

********************************************************************************
*Figure 3: Which type of contact with asylum seekers changes?
********************************************************************************

***
global an = "contact_res contact_public contact_work contact_close"
***

eststo noasylum1: mean contact_res contact_public contact_work contact_close [pw=weight2] if asylum==0 
eststo asylum1:  mean contact_res contact_public contact_work contact_close [pw=weight2] if asylum==1

coefplot ///
(asylum1, label(Asylum seekers in municipality) ciopts(lcolor(black black))  ///
mcolor(black)) (noasylum1, label(No asylum seekers in municipality) ciopts(  ///
lcolor(gs10 gs10)) mcolor(gs10)),bgcolor(white) label msymbol(o) recast      ///
(scatter) levels(95 90) xlabel(0 (.1) .5) legend(ring(0) pos(4) rows(2)      ///
region(color(white))) xsize(7) ylabel(1 "... in residential area (0-1)" 2    ///
"... in public (0-1)" 3 "... in work/education context (0-1)" 4				 ///
"... in personal realm (0-1)") ytitle("Respondent share with contact ...") scheme(plotplain)

graph export figures\Fig3.png, width(4000) replace

********************************************************************************
*Figure 4: Attitudinal effects of asylum seeker housing
********************************************************************************

***
global an = " revthreat2 antimuslim att_imm3 salient"
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
}
coefplot $an, ///
xline(0) legend(off) levels(95 90) xlabel(-.05(.05).4) mcolor(black)         ///
ciopts(lcolor(black black) ) msymbol(o) xscale(range(-.05 .4)) keep(asylum)  ///
mlcolor(black) ylabel(none) yline(.8) yline(1) yline(1.2) scheme(plotplain)  ///
text(1.35 .2 "Issue salience: asylum/immigration (0-1)", size(small) j(l)) 	 ///
text(1.15 .2 "Anti-immigration attitudes (1-5)", size(small) j(l)) 			 ///
text(0.95 .2 "Anti-muslim attitudes (1-5)", size(small) j(l)) 				 ///
text(0.75 .2 "Overall index of anti-asylum seeker attitudes (1-5)", size(small) j(l))

graph export figures\Fig4.png, width(4000) replace

********************************************************************************
*Figure 5: Effects of housing asylum seekers on party preferences and voting behavior
********************************************************************************

***
global an = "to2_01 hofer1 hofer2 fpoe_pv2_01 fpoe_vi2 "
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
}

coefplot to2_01 hofer1 hofer2 fpoe_pv2_01 fpoe_vi2 , level(95 90) scheme(plotplain) ///
xline(0, lpattern(dash)) legend(off) msymbol(o) mcolor(black) ciopts(lcolor(black   ///
black) ) mlcolor(black) xscale(range(-.1 .25)) xlabel(-.1(.05).25) ylabel(none)     ///
text(0.70 .1 "Turnout intention (0-1, cont.)", size(vsmall) j(l)) 					///
text(0.88 .1 "Past vote: Hofer (FPÖ), Round 1 (0-1)", size(vsmall) j(l)) 			///
text(1.05 .1 "Past vote: Hofer (FPÖ), Round 2 (0-1)", size(vsmall) j(l)) 			///
text(1.20 .1 "Sympathy: FPÖ (0-1, cont.)", size(vsmall) j(l))						///
text(1.37 .1 "Vote intention: FPÖ (0-1)", size(vsmall) j(l))					 	///
yline(.76) yline(.93) yline(1.10) yline(1.27) keep(asylum)

graph export figures\Fig5.png, width(4000) replace
 
*______________________________________________________________________________________________________________
****************************************************************************************************************************************************************
*TABLES IN APPENDIX
*______________________________________________________________________________________________________________
****************************************************************************************************************************************************************

********************************************************************************
*Table A4.1: Summary statistics for variables used in entropy balancing
********************************************************************************

***
global an = "contact norefugees revthreat2 promuslim2  att_imm2 fpoe_vi2"
***

eststo clear

eststo: estpost tabstat male age kids religion churchgoing union migrant     ///
goodincome edu_indicator* employ*indicator? area_indicator? state_indicator? ///
to13 to_trend fpoe13 fpoe_trend lnpop15 pop15del3_sh  forpop15_sh            ///
forpop15_sh_del3 unemp15_sh unemp15_sh_del3, by(noasyl) columns(statistics)  ///
statistics(mean sd min max n)  

esttab .                    ///
using "tables/TabA4-1.tex"  ///
, cells("mean(fmt(a2)) sd min max count") stats(N) label unstack replace ///
nonumbers  eqlabels("Asylum seekers present" "No asylum seekers present" "Total", span prefix(\multicolumn{@span}{c}{) suffix(}) ) 

********************************************************************************
*Table A4.2: Does the treatment increase presence perception of/contact with refugees
********************************************************************************

***
global an = "contact_bin contact refugees " 
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new  
estimates store `x'
estadd local Entropy_balancing "Yes"
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'
estadd scalar Control_sd = sd[1,1] : `x'
estadd scalar R2 = e(r2) : `x'
}

***
global an = "contact_bin refugees"
***

foreach x in $an {
svyset randomid [pweight=weight2]
eststo `x'3: svy: logit `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new  
estimates store `x'3
estadd local Entropy_balancing "Yes"
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'3
estadd scalar Control_sd = sd[1,1] : `x'3
estadd scalar R2 = e(r2_p) : `x'3
}

esttab                       ///
using "tables/TabA4-2.tex"   ///
, replace compress stats(Entropy_balancing N R2 Control_mean Control_sd, fmt(0 0 2)) b(2) se(2)       ///
star(* 0.10 ** 0.05 *** 0.01) label ///
indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
 mgroups("OLS regression" "Logistic regression", pattern(1 0 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span) 			  ///
postfoot("\hline\hline" "\end{tabular}" "}" ) eqlabels(none)

********************************************************************************
*Table A4.3: Type of contact that changes
********************************************************************************

***
global an = "contact_res contact_public contact_work contact_close"
***

eststo clear

foreach x in $an { 

svyset randomid [pweight=weight2]
eststo `x'_OLS: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
estadd local Entropy_balancing "Yes" : `x'_OLS
estadd local Model "OLS" : `x'_OLS
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_OLS
estadd scalar Control_sd = sd[1,1] : `x'_OLS


svyset randomid [pweight=weight2]
eststo `x'_logit: svy: logistic `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
estadd local Entropy_balancing "Yes" : `x'_logit
estadd local Model "Logit" : `x'_logit
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_logit
estadd scalar Control_sd = sd[1,1] : `x'_logit
}

esttab contact_res* contact_public* contact_work* contact_close* ///
using "tables/TabA4-3.tex" ///
, replace compress stats(Model Entropy_balancing N r2 Control_mean Control_sd, ///
fmt(0 0 0 2)) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) nomtitles label ///
indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
 mgroups("contact in residential area" "public" "work or educational context" "personal realm", pattern(1 0 1 0 1 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
eqlabels(none) postfoot("\hline\hline" "\end{tabular}" "}")

********************************************************************************
*Table A4.4: Impact on group threat
********************************************************************************

***
global an = " revthreat2 reveconthreat_as revsecurity_as reveconreas_as revethical_as "
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x'_an: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
estimates store `x'
estadd local Entropy_balancing "Yes" : `x'_an
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_an
estadd scalar Control_sd = sd[1,1] : `x'_an
}

esttab  ///
using "tables/TabA4-4.tex" ///
, replace compress stats(Entropy_balancing N r2  Control_mean Control_sd, fmt(0 0 2)) b(2) se(2)      ///
star(* 0.10 ** 0.05 *** 0.01) label indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
 postfoot("\hline\hline" "\end{tabular}" "}")

********************************************************************************
*Table A4.5: Effects on attitudes towards refugees/asylum seekers
********************************************************************************

global an = "integration_bin generosity welfare salient imm_headline2"

eststo clear
foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x'_an: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
estimates store `x'
estadd local Entropy_balancing "Yes" : `x'_an
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_an
estadd scalar Control_sd = sd[1,1] : `x'_an
}

esttab  ///
using "tables/TabA4-5.tex" ///
, replace compress stats(Entropy_balancing N r2  Control_mean Control_sd, fmt(0 0 2)) b(2) se(2) 	  ///					///
star(* 0.10 ** 0.05 *** 0.01) label indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
postfoot("\hline\hline" "\end{tabular}" "}")

********************************************************************************
*Table A4.6: Effects on broader attitudes
********************************************************************************

***
global an = "antimuslim imm_control att_imm3 " 
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x'_an: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
estimates store `x'
estadd local Entropy_balancing "Yes" : `x'_an
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_an
estadd scalar Control_sd = sd[1,1] : `x'_an
}

esttab  ///
 using "tables/TabA4-6.tex" ///
, replace compress stats(Entropy_balancing N r2 Control_mean Control_sd, fmt(0 0 2)) b(2) se(2)		  ///
star(* 0.10 ** 0.05 *** 0.01) label ///
indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
postfoot("\hline\hline" "\end{tabular}" "}")

********************************************************************************
*Table A4.7: Impact on political preferences and voting behavior
********************************************************************************

***
global an = "to2_01 hofer1 hofer2 fpoe_pv2_01 fpoe_vi2" 
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x'_an: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
estadd local Entropy_balancing "Yes"
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_an
estadd scalar Control_sd = sd[1,1] : `x'_an
}

esttab   ///
using "tables/TabA4-7.tex" ///
, replace compress stats(Entropy_balancing N r2  Control_mean Control_sd, fmt(0 0 2)) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) label ///
indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
postfoot("\hline\hline" "\end{tabular}" "}")

********************************************************************************
*Table A4.8: Side-by-side comparison of linear vs. logistic regression estimates for binary dependent variables of Figure 4 and 5
********************************************************************************

***
global an = "salient hofer1 hofer2 fpoe_vi2 "
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x'_OLS: svy: reg `x' asylum  $sociodem_cont2 $sociodem_cat2 $municip_new 
estadd local Entropy_balancing "Yes"
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_OLS
estadd scalar Control_sd = sd[1,1] : `x'_OLS
}

foreach x in  $an {
svyset randomid [pweight=weight2]
quietly eststo `x'_logit: svy: logit `x' asylum  $sociodem_cont2 $sociodem_cat2 $municip_new 
estadd local Entropy_balancing "Yes"
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_logit
estadd scalar Control_sd = sd[1,1] : `x'_logit
}

esttab  ///
using "tables/TabA4-8.tex" ///
, replace compress stats(Entropy_balancing N  r2  Control_mean Control_sd, fmt(0 0 2))  b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) label ///
indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
mgroups("OLS regression" "Logistic regression", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
postfoot("\hline\hline" "\end{tabular}" "}") eqlabels(none)

********************************************************************************
*Table A5.1: Results for impact on contact, attitudes and behavior with nearest neighbour matching
********************************************************************************

eststo clear

qui: eststo: teffects nnmatch (contact $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (refugees $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (contact_res $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (contact_public $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (contact_work $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (contact_close $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)

qui: eststo: teffects nnmatch (revthreat2 $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (antimuslim $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (att_imm3 $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (salient $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)

qui: eststo: teffects nnmatch (to2_01 $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (hofer1 $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (hofer2 $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (fpoe_pv2_01 $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)
qui: eststo: teffects nnmatch (fpoe_vi2 $sociodem_cont2 $sociodem_cat2 $municip_new) (noasyl), atet nneighbor(1) biasadj($sociodem_cont2 $sociodem_cat2 $municip_new) vce($se)

esttab   ///
using "tables/TabA5-1.tex" ///
, replace compress label stats( N, fmt(0) ) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) ///
coeflabels(r1vs0.noasyl "No asylum seekers")  				         ///
mgroups("Contact variables" "Attitudes", pattern(1 0 0 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
postfoot("\hline\hline" "\end{tabular}" "}") 

********************************************************************************
*Table A5.2: Effects of contact type by treatment exposure (with population weights)
********************************************************************************

***
global an = "contact_res contact_public contact_work contact_close"
***

eststo clear

foreach x in $an { 
svyset randomid [pweight=weight2_pop]
eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
estadd local Entropy_balancing "Yes"
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'
estadd scalar Control_sd = sd[1,1] : `x'
}

esttab  ///
///using "tables/TabA5-2.tex" ///
, replace compress stats(Entropy_balancing N r2 Control_mean Control_sd, fmt(0 0 2)) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) label ///
indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
postfoot("\hline\hline" "\end{tabular}" "}")

********************************************************************************
*Table A5.3: Results for impact on refugee and immigration attitudes - unweighted results - part 1
********************************************************************************

***
global an = "revthreat2 reveconthreat_as revsecurity_as reveconreas_as revethical_as integration_bin generosity welfare salient imm_headline2" // att_imm_cul att_imm_econ
***

eststo clear

foreach x in $an {
quietly eststo `x'_an: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new, cluster(randomid)
estadd local Entropy_balancing "No"
quietly sum `x' if asylum==0
estadd scalar Control_mean = r(mean) : `x'_an
estadd scalar Control_sd = r(sd) : `x'_an
}

esttab ///
using "tables/TabA5-3.tex" ///
, replace compress stats(Entropy_balancing N r2 Control_mean Control_sd, fmt(0 0 2)) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) label ///
indicate("Macro = *land* $municip_new" "Micro = $sociodem_cont2 $sociodem_cat_indic2") nonote

********************************************************************************
*Table A5.4: Results for impact on refugee and immigration attitudes - unweighted results - part 2
********************************************************************************

***
global an = "antimuslim imm_control att_imm3 to2_01 hofer1 hofer2 fpoe_pv2_01 fpoe_vi2"
***

eststo clear

foreach x in $an {
quietly eststo `x'_an: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new, cluster(randomid)
estadd local Entropy_balancing "No"
quietly sum `x' if asylum==0
estadd scalar Control_mean = r(mean) : `x'_an
estadd scalar Control_sd = r(sd) : `x'_an
}

esttab ///
using "tables/TabA5-4.tex" ///
, replace compress stats(Entropy_balancing N r2 Control_mean Control_sd, fmt(0 0 2)) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) label ///
indicate("Macro = *land* $municip_new" "Micro = $sociodem_cont2 $sociodem_cat_indic2") nonote

********************************************************************************
*Table A6.1: Subgroup results: Male/female

*Table A6.2: Subgroup results: High/low education

*Table A6.3: Subgroup results: Above/below median age

*Table A6.4: Subgroup results: Above/below median share of immigrants in municipality pre-2015
********************************************************************************


*******
*subgroup loop

eststo clear

foreach v in male medianage highedu medianforeign medianfpoe {

foreach z in 0 1 {

preserve
keep if `v' == `z'

global an = "revthreat2 antimuslim att_imm3"

foreach x in $an {
svyset randomid $weight2
eststo `v'`x'`z'_an: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new
quietly sum `x' if asylum==0
estadd local Entropy_balancing "Yes" : `v'`x'`z'_an
estadd scalar Control_mean = r(mean) : `v'`x'`z'_an
estadd scalar Control_sd = r(sd) : `v'`x'`z'_an
}

restore
}

if "`v'" == "male"  {
   local save = "TabA6-1"
   }
else if "`v'" == "medianage" {
   local save = "TabA6-3"
   }
else if "`v'" == "highedu" {
   local save = "TabA6-2"
   }
else if "`v'" == "medianforeign" {
   local save = "TabA6-4"
   }
else if "`v'" == "medianfpoe" {
   local save = "TabA6-5"
  }

esttab *`v'* ///
using "tables/`save'.tex" ///
, nonotes replace compress stats(Entropy_balancing N r2 Control_mean Control_sd, fmt(0 0 2)) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) label ///
indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
mgroups("`v'==0" "`v'==1", pattern(1 0 0 1 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span) 
}


********************************************************************************
*Table A7.1: Effects of contact type by treatment exposure
********************************************************************************

***
global an = "contact_res contact_public contact_work contact_close"
***

eststo clear

foreach z in high low {
foreach x in $an { 

svyset randomid [pweight=weight2_`z']
eststo `x'`z': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
estadd local Entropy_balancing "Yes" : `x'`z'
svy: mean `x' if asylum==0 & noasylvs`z' != .
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar control_mean = mean[1,1] : `x'`z'
estadd scalar control_sd = sd[1,1] : `x'`z'
}
}

esttab contact_*low contact_*high ///
using "tables/TabA7-1.tex" ///
, replace compress stats(Entropy_balancing N r2 control_mean control_sd, fmt(0 0 2)) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) label ///
indicate( "Macro controls = *land* *areaofresidence $municip_new" "Micro controls = $sociodem_cont2 *employment* *education*") ///
mtitle("contact in residential area" "public" "work or educational context" "personal realm" "Contact in residential area" "public" "work or educational context" "personal realm") ///
mgroups("Below median exposure" "Above median exposure" , pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
postfoot("\hline\hline" "\end{tabular}" "}")

********************************************************************************
*Table A8.1: Campaign Effects W5
********************************************************************************

***
global an = " impersonalcontactw5 localcontactw5 anycontactw5 impersonalcontactw5_oevp localcontactw5_oevp anycontactw5_oevp impersonalcontactw5_spoe localcontactw5_spoe anycontactw5_spoe impersonalcontactw5_fpoe localcontactw5_fpoe anycontactw5_fpoe impersonalcontactw5_grn localcontactw5_grn anycontactw5_grn"
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x'_an: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
estadd local Entropy_balancing "Yes" : `x'_an 
svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_an
estadd scalar Control_sd = sd[1,1] : `x'_an
}


esttab ///
using "tables/TabA8-1.tex" ///
, replace compress stats(Entropy_balancing N r2 Control_mean Control_sd, fmt(0 0 2)) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) label ///
indicate("Macro = *land* $municip_new" "Micro = $sociodem_cont2 $sociodem_cat_indic2") nonote

*______________________________________________________________________________________________________________
****************************************************************************************************************************************************************
*FIGURES IN APPENDIX
*______________________________________________________________________________________________________________
****************************************************************************************************************************************************************

********************************************************************************
*Figure A1.1: Attitudinal effects
********************************************************************************

***
global an = "revthreat2 reveconthreat_as revsecurity_as reveconreas_as revethical_as"
***

eststo clear
foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x'_an: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
}

coefplot revthreat2_an reveconthreat_as_an revsecurity_as_an reveconreas_as_an revethical_as_an, ///
scheme(plotplain) xline(0, lpattern(dash)) legend(off) levels(95 90) msymbol(o)                  ///
mcolor(black) ciopts(lcolor(black black) ) mlcolor(black) recast(rcap) yline(.76) yline(.93)     ///
xscale(range(-.2 .6)) xlabel(-.2(.2).6) ylabel(none) keep(asylum)  yline(1.10) yline(1.27)       ///
text(0.70 .2 "Overall index of group threat (1-5)", size(vsmall) j(l)) 			   		///
text(0.87 .2 "Asylum seekers take away jobs (1-5)", size(vsmall) j(l)) 			  		///
text(1.04 .2 "Refugees should not get same social benefits (1-5)", size(vsmall) j(l))   ///
text(1.21 .2 "Motive for flight economic (1-5)", size(vsmall) j(l)) 					///
text(1.38 .2 "No moral obligation to take in asylum seekers (1-5)", size(vsmall) j(l))  
									  
graph export figures\FigA1-1.png, width(4000) replace

********************************************************************************
*Figure A4.1: Weighted distribution of contact variable in municipalities with and without asylum seekers
********************************************************************************

byhist contact [pweight=weight2], by(asylum) frac discrete
// legend edits
gr_edit .legend.Edit , style(cols(2)) style(rows(0)) keepstyles 
gr_edit .legend.plotregion1.label[1].text = {}
gr_edit .legend.plotregion1.label[1].text.Arrpush no
gr_edit .legend.plotregion1.label[2].text = {}
gr_edit .legend.plotregion1.label[2].text.Arrpush yes
gr_edit .legend.title.text = {}
gr_edit .legend.title.text.Arrpush Asylum seekers in municipality
// xaxis edits
gr_edit .xaxis1.major.num_rule_ticks = 5
gr_edit .xaxis1.edit_tick 1 0 `"never"', tickset(major)
gr_edit .xaxis1.major.num_rule_ticks = 4
gr_edit .xaxis1.edit_tick 1 1 `"monthly/less"', tickset(major)
gr_edit .xaxis1.major.num_rule_ticks = 3
gr_edit .xaxis1.edit_tick 1 2 `"> once/month"', tickset(major)
gr_edit .xaxis1.major.num_rule_ticks = 2
gr_edit .xaxis1.edit_tick 1 3 `"> once/week"', tickset(major)
gr_edit .xaxis1.major.num_rule_ticks = 1
gr_edit .xaxis1.edit_tick 1 4 `"daily"', tickset(major)
// background edit
gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
gr_edit .style.editstyle boxstyle(linestyle(color(white))) editcopy
// title edit
gr_edit .legend.title.style.editstyle size(mediumsmall) editcopy
gr_edit .legend.title.style.editstyle color(black) editcopy

graph export figures\FigA4-1.png, width(4000) replace

********************************************************************************
*Figure A4.2: Weighted distribution of group threat variable in municipalities with and without asylum seekers
********************************************************************************

sort cumnoasyl cumasyl 

line cumnoasyl revthreat2 || line cumasyl revthreat2, 				   /// 
legend(label(1 "no asylum seekers") label(2 "asylum seekers") cols(2)) ///
ytitle("Cumulative distribution function") lpattern(solid)

// background edit
gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
gr_edit .style.editstyle boxstyle(linestyle(color(white))) editcopy

graph export figures\FigA4-2.png, width(2000) replace

********************************************************************************
*Figure A5.1: Effects under different specifications of the entropy balancing
********************************************************************************

global a = "lnpop15 i.land "
global b = "$agg $sociodem_cont2 i.employment i.education $municip_new"
global c = "$agg $sociodem_cont2 $sociodem_cat2  lnpop15" 
global d = "$sociodem_cont2 $sociodem_cat2 $municip_new"
global e = "$agg  $sociodem_cat1 $municip_new"
global f = "$agg $sociodem_cont2 $sociodem_cat2 $municip_new"

local a = "Population and state only" 
local b = "Without state and rurality"
local c = "Without socio-demographics (unemployment, foreign pop. and deltas)" 
local d = "Without political variables (turnout/FPOE)"
local e = "Without individual level"
local f = "Population, state and political, socio-dem., rural., individ. variables (full set)"

foreach x in a b c d e f {

capture drop weight`x'

ebalance noasyl  $`x' /// 
, targets(1)   //  
gen weight`x' = _webal

global weight_n`x'  = "[pw=weight`x']"
}

foreach z in a b c d e f  {

***
global an = "contact revthreat2 antimuslim att_imm3 fpoe_vi2"
***

eststo clear

foreach x in $an {
svyset randomid [pw=weight`z']
quietly eststo `x': svy: reg `x' asylum $`z'
estimates store `x'
}
coefplot $an , /// 
scheme(plotplain) xline(0, lpattern(dash)) legend(off) levels(95 90)      		///
msymbol(o) mcolor(black) ciopts(lcolor(black black) ) mlcolor(black) 			///
xscale(range(-.1 .4)) xlabel(-.1(.1).4) ylabel(none) 							///
text(0.73 .2 "Contact with refugees (1-5)", size(small) j(l)) 						   ///
text(0.90 .2 "Overall index of anti-asylum seeker attitudes (1-5)", size(small) j(l))  ///
text(1.07 .2 "Anti-muslim attitudes (1-5)", size(small) j(l)) 						   ///
text(1.24 .2 "Anti-immigration attitudes (1-5)", size(small) j(l))					   ///
text(1.41 .2 "FPOE vote (0-1)", size(small) j(l))									   ///
									   ///
title(`"``z''"', size(small)) keep(asylum)  saving(m`z'sense.gph, replace)
}

graph combine masense.gph mbsense.gph mcsense.gph mdsense.gph mesense.gph ///
mfsense.gph, col(2) scheme(plotplain)
 
graph export figures\FigA5-1.png, width(4000) replace

********************************************************************************
*Figure A5.2: Perceived presence and contact by treatment subgroups (with population weights)
********************************************************************************

***
global an = "contact refugees "
****

eststo clear

foreach x in $an { 

svyset randomid [pweight=weight2_pop]
eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new  
}

coefplot (refugees, offset(-0.375)) (contact, offset(0.125)), scheme(plotplain)  ///
xline(0, lpattern(dash)) legend(off) levels(95 90) msymbol(o) mcolor(black)        ///
ciopts(lcolor(black black)) mlcolor(black) xscale(range(-.1 .5)) xlabel(-.1(.1).5) ///
ylabel(none)  yscale(range(0.5 1.75)) yline(1.15, lpattern(dash)) 				   ///
text(1.5 .2 "Presence noted? (0-1)", size(small) j(l)) 					           ///
text(1 .2 "Intensity of contact (1-5)", size(small) j(l))                          ///
keep(asylum) graphregion(margin(0 0 +15 +15)) 

graph export figures\FigA5-2.png, width(4000) replace 
  
********************************************************************************
*Figure A5.3: Attitudinal effects (with population weights)
********************************************************************************

***
global an = "revthreat2 antimuslim att_imm3 salient"
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2_pop]
quietly eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
}
coefplot $an , ///
scheme(plotplain) xline(0, lpattern(dash)) legend(off) levels(95 90) msymbol(o) ///
mcolor(black) ciopts(lcolor(black black) ) mlcolor(black) xscale(range(-.1 .4)) ///
xlabel(-0.1(.1).4) ylabel(none) yline(.80) yline(1) yline(1.2) keep(asylum)     ///
text(0.75 .2 "Overall index of anti-asylum seeker attitudes (1-5)", size(small) j(l)) ///
text(0.95 .2 "Anti-muslim attitudes (1-5)", size(small) j(l)) 						  ///
text(1.15 .2 "Anti-immigration attitudes (1-5)", size(small) j(l)) 					  ///
text(1.35 .2 "Issue salience: asylum/immigration (0-1)", size(small) j(l)) 			 

graph export figures\FigA5-3.png, width(4000) replace

********************************************************************************
*Figure A5.4: Effects on voting behavior (with population weights)
********************************************************************************

***
global an = "to2_01 hofer1 hofer2 fpoe_pv2_01 fpoe_vi2" 
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2_pop]
quietly eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
}

coefplot to2_01 hofer1 hofer2 fpoe_pv2_01 fpoe_vi2 , level(95 90) scheme(plotplain) ///
xline(0, lpattern(dash)) legend(off) msymbol(o) mcolor(black) ciopts(lcolor			///
(black black) ) mlcolor(black) xscale(range(-.1 .3)) xlabel(-.1(.1).3) ylabel(none) ///
yline(.76) yline(.93) yline(1.10) yline(1.27) keep(asylum) 							///
text(0.70 .1 "Turnout intention (0-1, cont.)", size(vsmall) j(l)) 				///
text(0.88 .1 "Past vote: Hofer (FPÖ), Round 1 (0-1)", size(vsmall) j(l)) 		///
text(1.05 .1 "Past vote: Hofer (FPÖ), Round 2 (0-1)", size(vsmall) j(l)) 		///
text(1.21 .1 "Sympathy: FPÖ (0-1, cont.)", size(vsmall) j(l)) 					///
text(1.37 .1 "Vote intention: FPÖ (0-1)", size(vsmall) j(l)) 

graph export figures\FigA5-4.png, width(4000) replace

********************************************************************************
*Figure A6.1: Attitudinal effects in Upper Austria
********************************************************************************

***
global an = "revthreat2 antimuslim att_imm3 salient"
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new if sd4==4 
}
coefplot $an, ///
scheme(plotplain) xline(0, lpattern(dash)) legend(off) levels(95 90) msymbol(o)  ///
mcolor(black) ciopts(lcolor(black black) ) mlcolor(black) xscale(range(-.2 1.2)) ///
xlabel(-.2(.2)1.2) ylabel(none) yline(.80) yline(1) yline(1.2) keep(asylum)      ///
text(0.75 .4 "Overall index of anti-asylum seeker attitudes (1-5)", size(small) j(l))  ///
text(0.95 .4 "Anti-muslim attitudes (1-5)", size(small) j(l)) 						   ///
text(1.15 .4 "Anti-immigration attitudes (1-5)", size(small) j(l))					   ///
text(1.35 .4 "Issue salience: asylum/immigration (0-1)", size(small) j(l))			  

graph export figures\FigA6-1.png, width(4000) replace

********************************************************************************
*Figure A6.2: Effects on vote choice in Upper Austria
********************************************************************************

***
global an = "to2_01 hofer1 hofer2 fpoe_pv2_01 fpoe_vi2"
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new if sd4==4
}

coefplot to2_01 hofer1 hofer2 fpoe_pv2_01 fpoe_vi2 , level(95 90) scheme(plotplain) ///
xline(0, lpattern(dash)) legend(off) msymbol(o) mcolor(black) ciopts(lcolor(black   ///
black) ) mlcolor(black) xscale(range(-.1 .5)) xlabel(-.1(.1).5) ylabel(none)        ///
yline(.76) yline(.93) yline(1.10) yline(1.27) keep(asylum)							///
text(0.70 .1 "Turnout intention (0-1, cont.)", size(vsmall) j(l)) 		  ///
text(0.88 .1 "Past vote: Hofer (FPÖ), Round 1 (0-1)", size(vsmall) j(l))  ///
text(1.05 .1 "Past vote: Hofer (FPÖ), Round 2 (0-1)", size(vsmall) j(l))  ///
text(1.20 .1 "Sympathy: FPÖ (0-1, cont.)", size(vsmall) j(l)) 			  ///
text(1.37 .1 "Vote intention: FPÖ (0-1)", size(vsmall) j(l)) 		      

graph export figures\FigA6-2.png, width(4000) replace
 
********************************************************************************
*Figure A7.1: Distribution of intensive margin
********************************************************************************

hist Mar_Q if noasyl==0, xlabel(0(1)15, format(%3.0f)) xtick(0(0.5)15) width(0.25) ///
xtitle("March 2016 asylum seeker share of municipality population") scheme(plotplain)

graph export figures\FigA7-1.png, width(4000) replace
 
********************************************************************************
*Figure A7.2: Perceived presence and contact by treatment subgroups
********************************************************************************

***
global an = "contact refugees"  
***

eststo clear

foreach x in $an {

svyset randomid [pweight=weight2_low]
eststo `x'_low: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new  

svyset randomid [pweight=weight2_high]
eststo `x'_high: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new  
}

coefplot (refugees_low, offset(-0.475) msymbol(triangle) lstyle(dash))		 	         ///
(contact_low, offset(0) msymbol(triangle)) (refugees_high, offset(-0.375))	         ///
(contact_high, offset(0.125)), scheme(plotplain) xline(0, lpattern(dash))  	         ///
levels(95 90) msymbol(o) mcolor(black) ciopts(lcolor(black black)) mlcolor(black)        ///
xscale(range(-.1 .5)) xlabel(-.1(.1).5) ylabel(none)  yscale(range(0.5 1.75))            ///
yline(1.15, lpattern(dash)) text(1.25 .2 "Presence noted? (0-1)", size(small) j(l))	     ///
text(0.7 .2 "Intensity of contact (1-5)", size(small) j(l)) keep(asylum) 				 ///
graphregion(margin(0 0 +15 +15)) legend(label(3 "Below median exposure" ) 				 ///
label(9 "Above median exposure") order(9 3) pos(1) ring(0))

graph export figures\FigA7-2.png, width(4000) replace

********************************************************************************
*Figure A7.3: Attitudinal effects by high and low treatment exposure
********************************************************************************

***
global an = "revthreat2 antimuslim att_imm3 salient"
***

eststo clear

foreach z in low high {
foreach x in $an {
svyset randomid [pweight=weight2_`z']
quietly eststo `x'`z': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
}
}

coefplot (revthreat2low, msymbol(o)) revthreat2high (antimuslimlow, msymbol(o)) ///
antimuslimhigh (att_imm3low, msymbol(o)) att_imm3high (salientlow, msymbol(o))  ///
salienthigh, keep(asylum) xline(0) scheme(plotplain) xline(0, lpattern(dash))   ///
levels(95 90) msymbol(triangle) mcolor(black) ciopts(lcolor(black black))		///
mlcolor(black) xscale(range(-.3 .4)) xlabel(-.3(.1).4) ylabel(none)  			///
yline(.80) yline(1) yline(1.2) 													///
text(0.67 .18 "Overall index of anti-asylum seeker attitudes (1-5)", size(small) j(l)) ///
text(0.89 .18 "Anti-muslim attitudes (1-5)", size(small) j(l)) 						   ///
text(1.11 .18 "Anti-immigration attitudes (1-5)", size(small) j(l)) 				   ///
text(1.34 .18 "Issue salience: asylum/immigration (0-1)", size(small) j(l)) 		   ///
legend(label(3 "Below median exposure" ) label(6 "Above median exposure") order(3 6) pos(5) ring(0))

graph export figures\FigA7-3.png, width(4000) replace

********************************************************************************
*Figure A7.4: Effects on voting behavior by high and low treatment exposure
********************************************************************************

***
global an = "to2_01 hofer1 hofer2 fpoe_pv2_01 fpoe_vi2" 
***

eststo clear

foreach z in low high {
foreach x in $an {
svyset randomid [pweight=weight2_`z']
quietly eststo `x'`z'_an: svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
}
}

coefplot (to2_01low_an, msymbol(o)) (to2_01high_an, msymbol(triangle))       ///
(hofer1low_an, msymbol(o)) (hofer1high_an) (hofer2low_an, msymbol(o)) 	     ///
(hofer2high_an) (fpoe_pv2_01low_an, msymbol(o)) (fpoe_pv2_01high_an) 		 ///
(fpoe_vi2low_an, msymbol(o) ) (fpoe_vi2high_an) , keep(asylum) level(95 90)  ///
scheme(plotplain) xline(0, lpattern(dash))  msymbol(triangle) mcolor(black)  ///
ciopts(lcolor(black black) ) mlcolor(black) xscale(range(-.3 .3))            ///
xlabel(-.3(.1).3) ylabel(none) yline(.76) yline(.93) yline(1.10) yline(1.27) ///
text(0.64 .085 "Turnout intention (0-1, cont.)", size(vsmall) j(l)) 		 ///
text(0.82 .085 "Past vote: Hofer (FPÖ), Round 1 (0-1)", size(vsmall) j(l)) 	 ///
text(1.00 .085 "Past vote: Hofer (FPÖ), Round 2 (0-1)", size(vsmall) j(l)) 	 ///
text(1.18 .085 "Sympathy: FPÖ (0-1, cont.)", size(vsmall) j(l)) 			 ///
text(1.36 .085 "Vote intention: FPÖ (0-1)", size(vsmall) j(l))				 ///
legend(label(3 "Below median exposure" ) label(6 "Above median exposure") order(3 6) pos(1) ring(0))

graph export figures\FigA7-4.png, width(4000) replace

********************************************************************************
*Figure A8.1: Effects of asylum seeker presence on campaign contact
********************************************************************************

***
global an = "anycontactw5 localcontactw5 anycontactw5_fpoe localcontactw5_fpoe"
***

eststo clear

foreach x in $an {
svyset randomid [pweight=weight2]
quietly eststo `x': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
}
coefplot $an , ///
scheme(plotplain) xline(0, lpattern(dash)) legend(off) levels(95 90) keep(asylum) ///
msymbol(o) mcolor(black) ciopts(lcolor(black black)) mlcolor(black) yline(.80)    ///
xscale(range(-.1 .3)) xlabel(-.1(.1).3) ylabel(none) yline(1) yline(1.2)   	      ///
text(0.75 .1 "Any campaign contact (0-1)", size(small) j(l))				      ///
text(0.95 .1 "Personal campaign contact (0-1)", size(small) j(l)) 			      ///
text(1.15 .1 "Any campaign contact by FPÖ (0-1)", size(small) j(l))			      ///
text(1.35 .1 "Personal campaign contact by FPÖ (0-1)", size(small) j(l)) 	      ///

graph export figures\FigA8-1.png, width(4000) replace

********************************************************************************
*Figure A8.2: Effects of asylum seeker presence on campaign contact (by treatment subgroups)
********************************************************************************

***
global an = " anycontactw5 localcontactw5 anycontactw5_fpoe localcontactw5_fpoe"
***

eststo clear

foreach z in low high {
foreach x in $an {
svyset randomid [pweight=weight2_`z']
quietly eststo `x'`z': svy: reg `x' asylum $sociodem_cont2 $sociodem_cat2 $municip_new 
}
}

coefplot (anycontactw5low, msymbol(o)) anycontactw5high (localcontactw5low,		    ///
msymbol(o)) localcontactw5high (anycontactw5_fpoelow, msymbol(o)) 				    ///
anycontactw5_fpoehigh (localcontactw5_fpoelow, msymbol(o)) localcontactw5_fpoehigh, ///
keep(asylum) xline(0) scheme(plotplain) xline(0, lpattern(dash)) levels(95 90)      ///
msymbol(triangle) mcolor(black) ciopts(lcolor(black black) ) mlcolor(black)         ///
xscale(range(-.1 .4)) xlabel(-.1(.1).4) ylabel(none)							    ///	 											    ///
text(0.67 .15 "Any campaign contact (0-1)", size(small) j(l))					    ///
text(0.89 .15 "Personal campaign contact (0-1)", size(small) j(l))					///
text(1.11 .15 "Any campaign contact by FPÖ (0-1)", size(small) j(l)) 				///
text(1.33 .15 "Personal campaign contact by FPÖ (0-1)", size(small) j(l))			///
legend(label(3 "Below median exposure" ) label(6 "Above median exposure")			///
order(3 6) pos(7) ring(0)) yline(.80) yline(1) yline(1.2) 	

graph export figures\FigA8-2.png, width(4000) replace

********************************************************************************
********************************************************************************

****************************************************************************************************************************************************************
*load new data set

use datasources\placebo.dta, clear

****************************************************************************************************************************************************************
*treat new data set

*****
*create global macros 
global an = "integration generosity promuslim imm_worry imm_intensity imm_control att_imm imm_salient"
global char = "pol_interest_w1 democracy w1_quiz"
global pref = " fpoe_w1 oevp spoe eu_pref to part_ltw"
global sociodem_cont = "male age hhsize kids religion churchgoing union migrant goodincome hhinc"
global sociodem_cont2 = "male age kids religion union migrant goodincome"
global sociodem_cat = "i.land  i.employment i.education"
global sociodem_cat2 = " i.land i.employment i.education i.areaofresidence"
global municipality_new = "lnpop13 unemp13_sh unemp13_sh_del3 " 


********************************************************************************
*Creat Entropy Balancing Weights
********************************************************************************

capture drop weight
ebalance noasyl to08 to_trend fpoe_trend fpoe08 i.land $municipality_new $sociodem_cont2 $sociodem_cat2 , maxiter(400)   // male hhinc $polcont
gen weight = _webal

global weight = "[pw=weight]"

********************************************************************************
*Table A3.1: Balance in 2013 survey by 2015/16 asylum take-up for three groups
********************************************************************************

eststo clear

eststo k10: estpost ttest $sociodem_cont highedu fulltime rural $char $pref $an if inhabitants <= 10000, by(asylum)
eststo k10sept: estpost ttest $sociodem_cont highedu fulltime rural $char $pref $an if inhabitants <= 10000, by(asylum_sept)
eststo all: estpost ttest $sociodem_cont highedu fulltime rural $char $pref $an , by(asylum)

esttab k10 k10sept all ///
using "tables/TabA3-1.tex" ///
 , mtitles() label replace compress star(* 0.10 ** 0.05 *** 0.01) ///
 cells("mu_1(fmt(%12.2f) label(C)) mu_2(fmt(%12.2f) label(T)) b(fmt(%12.2f) star label(Diff-In-Means)) N_1(fmt(%12.0f) label(N C)) N_2(fmt(%12.0f) label(N T))" ///
 "mean mean se(par fmt(2))" ". . .")

*******************************************************************************
*Table A3.2: Placebo test with weights based on municipality and individual characteristics
********************************************************************************

label variable fpoe_w1 "FPOE vote intention"
label variable fpoe_cont "FPOE sympathy"
label variable to "Turnout itention"
label variable integration "Immigrants integrate well"
label variable generosity "Generosity in asylum acceptance"
label variable promuslim "Positive attitude towards muslims"
label variable imm_worry "Immigration not worrying"
label variable imm_intensity "Immigration intensity decreased"
label variable imm_control "Immigration under political control"
label variable att_imm "Positive attitude towards immigrants"
label variable imm_salient "Immigration most salient"

***
global an = "fpoe_w1 fpoe_cont to integration generosity promuslim imm_worry imm_intensity imm_control att_imm imm_salient"
***
eststo clear

foreach x in $an {
svyset gem_ID $weight
eststo `x'_an: svy: reg `x' asylum to08 to_trend fpoe_trend fpoe08 $municipality_new $sociodem_cont2 $sociodem_cat2  
estadd local Entropy_banalcing "Yes"
 svy: mean `x' if asylum==0
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : `x'_an
estadd scalar Control_sd = sd[1,1] : `x'_an
}

esttab ///
using "tables/TabA3-2.tex" ///
, replace compress stats(Entropy_banalcing N Control_mean Control_sd, fmt(0 0 2)) b(2) se(2) star(* 0.10 ** 0.05 *** 0.01) label ///
indicate("Macro controls =  ?.land  to08 to_trend fpoe_trend fpoe08 ?.areaofresidence"              ///
"Micro controls = ?.employment ?.education lnpop13 unemp13_sh unemp13_sh_del3 male age kids religion union migrant goodincome ") postfoot("\hline\hline" "\end{tabular}" "}")



***END OF FILE***
